<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=width-device,initial-scale=1.0,user-scalable=no" />
		<title>修改职业</title>		
		<link rel="stylesheet" href="js/bootstrap/css/bootstrap.css" />
		<link rel="stylesheet" href="js/datetimepicker/jquery.datetimepicker.css" />
	</head>
	<body>
		<div class="container">			
			
			<h2 class="page-header">修改职业</h2>
			
			<form id="form1" class="form-horizontal">				
				<div class="form-group">
					<label for="" class="col-sm-2">职业名称</label>
					<div class="col-sm-8">
						<input type="text" id="jobName" name="jobName" placeholder="请输入职业名称" class="form-control"/>
					</div>
				</div>	
				<div class="form-group">
					<label for="" class="col-sm-2">职业最低工资</label>
					<div class="col-sm-8">
						<input type="text" id="jobMinSal" name="jobMinSal" placeholder="请输入职业最低工资" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2">职业最高工资</label>
					<div class="col-sm-8">
						<input type="text" id="jobMaxSal" name="jobMaxSal" placeholder="请输入职业最高工资" class="form-control"/>
					</div>
				</div>
				
				
				<div class="form-group">
					<label for="" class="col-sm-2">所属专业</label>
					<div class="col-sm-8">
						<select name="majors.majorsId" id="majorsId" class="form-control">
							<option value="">请选择部门</option>
						</select>
					</div>
				</div>
				
				<div class="form-group">
					<label for="" class="col-sm-2">职业简介</label>
					<div class="col-sm-8">
						<textarea id="jobIntro" name="jobIntro" class="form-control"></textarea>
					</div>
				</div>				
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-8">
						<input type="hidden" id="jobId" name="jobId" />
						<input type="button" value="修改" id="updateBtn" class="btn btn-success" />
						<input type="button" value="取消" class="btn btn-warning" onclick="window.parent.layer.closeAll()" />
					</div>					
				</div>
			</form>	
		</div>		
		
		<script type="text/javascript" src="js/vue2.5.js" ></script>
		<script type="text/javascript" src="js/axios.min.js" ></script>
		<script type="text/javascript" src="js/jquery.js" ></script>
		<script type="text/javascript" src="js/global.js" ></script>
		<script type="text/javascript" src="js/bootstrap/js/bootstrap.js" ></script>
		<script type="text/javascript" src="js/layer/layer.js" ></script>
		<script type="text/javascript" src="js/datetimepicker/jquery.datetimepicker.js" ></script>
		<script type="text/javascript" src="js/param.js" ></script>
		<script>
		
			//统一设置ajax同步
			$.ajaxSetup({
				async:false
			});
			//动态生成部门列表框
			$.ajax({
				url:baseUrl + '/majors/query',
				type:'GET',
				dataType:'json'				
			})
			.done(function(data){				
				$.each(data, function(index,item) {					
					var opt = '<option value="' + item.majorsId + '">' + item.majorsName + '</option>';
					$('#majorsId').append(opt);
				});					
			})
			.fail(function(xhr,status,text){
				layer.msg('专业列表请求失败');				
			});
						
			//获得员工信息
			var jobId = getParam('jobId');
			
			//获得员工数据的数据模型中数组下标
			var index = getParam('index');
						
			$.getJSON(baseUrl + '/job/queryId',{jobId:jobId},function(data){
				$('#jobName').val(data.jobName);
				$('#jobMinSal').val(data.jobMinSal);
				$('#jobMaxSal').val(data.jobMaxSal);
				$('#jobIntro').val(data.jobIntro);
				$('#majorsId').val(data.majors.majorsId);
			})
			.error(function(){
				layer.msg('网络请求失败');
			});
			
			//表单验证函数
			function checkForm() {
				//邮箱验证
				//电话号码验证
				//工资验证（工资必须是职务范围之内的工资）
				//部门
				var majorsId = $('#majorsId');
				
				if (majorsId.val() == '') {
					layer.msg('请选择一个职业');
					majorsId.focus();
					return false;
				}
				return true;
			}
			
			
			//增加按钮单击事件
			$('#updateBtn').click(function(){
				
				//调用表单验证
				if ( !checkForm() )
					return;
					
				//ajax请求
				var params = $('#form1').serialize();
				
				$.post(baseUrl + '/job/update',params,function(data){
					layer.msg('修改职业成功');
					
					//修改前端员工数据
					var job = window.parent.vue.jobData[index];
					
					job.jobId = jobId;
					job.jobName = $('#jobName').val();
					job.jobMinSal = $('#jobMinSal').val();
					job.jobMaxSal = $('#jobMaxSal').val();
					job.majors.majorsName = $('#majorsId option:selected').text();
					job.jobIntro = $('#jobIntro').val();
										
					setTimeout(function(){												
						window.parent.layer.closeAll();
					},500);
				})
				.error(function(){
					layer.msg('修改职业请求失败');					
				});				
				
			});
			
		</script>		
	</body>
</html>